import { defineConfig } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import Components from 'unplugin-vue-components/vite'
import pkg from './package.json';
import dayjs from 'dayjs';
// 打包后静态资源的存放路径
const assetsDir = 'assets';

// __APP_INFO__
const { dependencies, devDependencies, name, version } = pkg;
const appVersion = dayjs().format('YYYYMMDDHHmm');
const lastBuildTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
const __APP_INFO__ = {
  pkg: { dependencies, devDependencies, name, version },
  version: appVersion,
  lastBuildTime,
  name:''
};


// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    uni(),
    Components({
      dts: true, // 生成类型声明文件
      dirs: ['src/components'], // 组件目录
      extensions: ['vue'],
      deep: true, // 深度扫描子目录
      resolvers: []
    })
  ],
  define: { __DEV__: process.env.NODE_ENV === 'development' },
  build: {
      assetsDir: assetsDir,
      sourcemap: false,
      chunkSizeWarningLimit: 1500,
      rollupOptions: {
        output: {
          entryFileNames: `${assetsDir}/[name].${appVersion}.js`,
          chunkFileNames: `${assetsDir}/[name].${appVersion}.js`,
          assetFileNames: `${assetsDir}/[ext]/[name].${appVersion}.[ext]`,
        },
      },
    },
});